package com.cicigodd.brick.plug.system.role.controller;

import com.cicigodd.brick.plug.annotation.repeatsubmit.RepeatSubmit;
import com.cicigodd.brick.plug.annotation.resource.DeleteResource;
import com.cicigodd.brick.plug.annotation.resource.PutResource;
import com.cicigodd.brick.plug.common.response.PageResult;
import com.cicigodd.brick.plug.common.response.Result;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import com.cicigodd.brick.plug.annotation.resource.PostResource;
import com.cicigodd.brick.plug.annotation.resource.GetResource;
import com.cicigodd.brick.plug.system.role.request.SysRoleAddRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleDeleteRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleDetailRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleEditRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleListRequest;
import com.cicigodd.brick.plug.system.role.response.SysRoleDetailResponse;
import com.cicigodd.brick.plug.system.role.response.SysRoleListResponse;
import com.cicigodd.brick.plug.system.role.service.SysRoleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;


@Api(tags = "角色管理")
@RestController
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @RepeatSubmit
    @ApiOperation(value = "角色管理添加", notes = "角色管理添加")
    @PostResource(name = "角色管理添加", path = "/sysRole/add")
    public Result add(@RequestBody @Validated SysRoleAddRequest sysRoleAddRequest) {
        sysRoleService.add(sysRoleAddRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色管理删除", notes = "根据id删除")
    @DeleteResource(name = "角色管理删除", path = "/sysRole/delete")
    public Result delete(@Validated SysRoleDeleteRequest sysRoleDeleteRequest) {
        sysRoleService.delete(sysRoleDeleteRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色管理编辑", notes = "角色管理编辑")
    @PutResource(name = "角色管理编辑", path = "/sysRole/edit")
    public Result edit(@RequestBody @Validated SysRoleEditRequest sysRoleEditRequest) {
        sysRoleService.edit(sysRoleEditRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色管理详情", notes = "根据id查询")
    @GetResource(name = "角色管理详情", path = "/sysRole/detail")
    public Result<SysRoleDetailResponse> detail(SysRoleDetailRequest sysRoleDetailRequest) {
        SysRoleDetailResponse detail = sysRoleService.detail(sysRoleDetailRequest);
        return ResultGenerator.successResult(detail);
    }


    @ApiOperation(value = "角色管理分页列表", notes = "角色管理分页列表")
    @GetResource(name = "角色管理分页列表", path = "/sysRole/list")
    public Result<PageResult<SysRoleListResponse>> list(SysRoleListRequest sysRoleListRequest) {
        PageResult<SysRoleListResponse> pageList =  sysRoleService.list(sysRoleListRequest);
        return ResultGenerator.successResult(pageList);
    }

    @ApiOperation(value = "角色管理列表", notes = "角色管理列表")
    @GetResource(name = "角色管理列表", path = "/sysRole/listAll")
    public Result<List<SysRoleListResponse>> listAll(SysRoleListRequest sysRoleListRequest) {
        List<SysRoleListResponse> pageList =  sysRoleService.listAll(sysRoleListRequest);
        return ResultGenerator.successResult(pageList);
    }

    @ApiOperation(value = "获取角色绑定的菜单", notes = "获取角色绑定的菜单")
    @GetResource(name = "获取角色绑定的菜单", path = "/sysRole/getMenuIdsByRoleId")
    public Result<List<Integer>> getMenuIdsByRoleId(SysRoleDetailRequest sysRoleDetailRequest) {
        List<Integer> list =  sysRoleService.getMenuIdsByRoleId(sysRoleDetailRequest.getId());
        return ResultGenerator.successResult(list);
    }
}
